<?php

    namespace MyApp\FilmothequeBundle\Controller;

    use Symfony\Component\DependencyInjection\ContainerAware ;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    use MyApp\FilmothequeBundle\Entity\Categorie;

    class DefaultController extends ContainerAware
    {

        public function indexAction()
        {
                $em = $this->container->get('doctrine.orm.entity_manager');
                $categories = $em->getRepository('MyappFilmothequeBundle:Categorie')->findAll();

                return $this->container->get('templating')->renderResponse('MyappFilmothequeBundle:Default:index.html.twig',
                        array('categories' => $categories)
                );
        }
        
        public function enregistrerCategorieAction()
        {
            $em = $this->container->get('doctrine.orm.entity_manager');

            $categorie1 = new Categorie();
            $categorie1->setNom('Comedie');
            $em->persist($categorie1);

            $categorie2 = new Categorie();
            $categorie2->setNom('Science-fiction');
            $em->persist($categorie2);

            //$em->flush();

            $message = 'Categories creees avec succes';

            return $this->container->get('templating')->renderResponse('MyappFilmothequeBundle:Default:index.html.twig',
              array('message' => $message)
            );
        }
    }

?>